''' Barcode check digit checker. The Barcode is explained here: https://www.youtube.com/watch?v=e6aR1k-ympo ''' def weighting(digit, weight): n=digit*weight return n evenWeight=3 oddWeight=1 t=0 number=[0,5,1,0,0,0,0,1,2,5,1,7] #This is a 12 digit bar code l=(len(number)) for i in range (0, l-1,2): t=t+ weighting(number[i],evenWeight) for i in range (1, l-1,2): t=t+weighting(number[i],oddWeight) print(t) remainder = t % 10 calcedCD= (10 - remainder) % 10 if number[l-1] == calcedCD: print("The calculated check digit and the last digit match!") else: print("Oops! The calculated check digit doesn't match the last one read in.")